<?php


	include_once("cmsConfig.php");

	/**
		a class to store details about errors etc..

	*/
	

	define("CMS_STATUS_ERROR",1);
	define("CMS_STATUS_WARNING",2);
	define("CMS_STATUS_MESSAGE",3);
	define("CMS_STATUS_NOTICE",4);

//	$CMS_ERROR_DICT = array(
//			'f_NOT_NULL' => "%s is a required field",
//			'f_NOT_VALID' => "%s is contains invalid data"
//		);

	class CmsStatusMessage {
	

		var $hasErrors = false;
		var $messages = array();
		
		var $CMS_ERROR_DICT = array(
			'f_NOT_NULL' => " is a required field",
			'f_NOT_VALID' => " contains invalid data",
			'f_PERM_NO_ADD' => "you are not allowed to add this content",
			'f_PERM_NO_EDIT' => "you are not allowed to edit this content",
			'f_PERM_NOT_IN_GROUP' => "User not is not in the specified group"
		);
					
		function addValidationMessageForKey( $key, $message, $messageType) {
	
			if ( !isset($this->messages)) {
				$this->messages = array();
			}
			
			if ( !isset($this->messages[ $key ])) {
				$this->messages[ $key ] = array();
			}
			
			switch ($messageType) {
				case CMS_STATUS_ERROR:
					$this->hasErrors = true;
				break;
			}
			$this->messages[ $key ][] = array("message" => $message, "messageType" => $messageType);
		}
	
		//this works nice.. except.. in the case where we are using different field names..
		//there is also no knowledge of what the forms are actually
		//supposed to be titled either..
		function getMessageForKey($key){
			//this will look up a localised/site specific message..possibly..
			if (isset($this->messages[ $key ][0][ 'message' ] )) {
				return sprintf( $this->CMS_ERROR_DICT[ $this->messages[ $key ][0][ 'message' ] ], $key);
			}		
		}
		
	}
	
?>